<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
<script src="${pageContext.request.contextPath}/layui/jquery2.1.1.js"></script>
<script src="${pageContext.request.contextPath}/layui/lay/modules/layer.js"></script>
<script src="${pageContext.request.contextPath}/layui/lay/modules/table.js"></script>
<script src="${pageContext.request.contextPath}/layui/lay/modules/form.js"></script>
</head>
<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>采购单审核</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form class="layui-form">
    <div class="layui-form-item">
      <label class="layui-form-label">采购单编号</label>
      <div class="layui-input-inline">
        <input type="text" id="number" name="number" autocomplete="off" class="layui-input" >
      </div>
      <label class="layui-form-label">采购时间</label>
      <div class="layui-input-inline">
        <input type="date" name="start_time" id="start_time" autocomplete="off" class="layui-input" >
      </div>
      <div class="layui-form-mid">-</div>
      <div class="layui-input-inline">
        <input type="date" name="end_time" id="end_time" autocomplete="off" class="layui-input" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">金额</label>
      <div class="layui-input-inline">
        <input type="text" id="lowMoney" name="lowMoney" autocomplete="off" class="layui-input" >
      </div>
      <div class="layui-form-mid">-</div>
      <div class="layui-input-inline">
        <input type="text" id="highMoney" name="highMoney" autocomplete="off" class="layui-input" >
      </div>
      <div class="layui-btn-container">
        <button type="button" class="layui-btn btn-search"><i class="layui-icon">&#xe615;</i>查询</button>
      </div>
    </div>
    <table id="PurchaseTable" lay-filter="PurchaseTable"></table>
  </form>
</div>
<script>
  layui.use(['table', 'form','laydate'], function () {
    var table = layui.table,
            form = layui.form,
            util = layui.util,
            laydate = layui.laydate,
            $ = layui.jquery;
    form.render();
    laydate.render({
      elem: '#start_time',
      format: 'yyyy-MM-dd',
      done: function (value, date, endDate) {
        var startDate = new Date(value).getTime();
        var endTime = new Date($('#end_time').val()).getTime();
        if (endTime < startDate) {
          layer.msg('结束时间不能小于开始时间');
          $('#start_time').val('');
        }
      }
    });
    laydate.render({ //结束时间
      elem: '#end_time',
      format: 'yyyy-MM-dd',
      done: function (value, date, endDate) {
        var startDate = new Date($('#start_time').val()).getTime();
        var endTime = new Date(value).getTime();
        if (endTime < startDate) {
          layer.msg('结束时间不能小于开始时间');
          $('#end_time').val('');
        }
      }
    });

    //第一个实例
    table.render({
      elem: '#PurchaseTable'
      ,height: 400
      ,url: '/PurchaseOrder/getAllPurchaseOrderAuditList' //数据接口
      ,cols: [[ //表头
        {field: '_id', title: '序号', width:130, type:"numbers", fixed: 'left',align: "center" }
        ,{field: 'id', title: '序号', width:130, sort: true, fixed: 'left',align: "center" }
        ,{field: 'number', title: '采购单编号', width:210, sort: true,align: "center"}
        ,{field: 'poTime', title: '采购时间', width:210,align: "center",
          templet:function(res){
            if(res.poTime != null){
              return util.toDateString(res.poTime, "yyyy-MM-dd HH:mm:ss")
            }else{
              return ""
            }
        }}
        ,{field: 'amount', title: '金额', width:172,align: "center",
          templet: function (res) {
            return '￥'+res.amount;
          }}
        ,{field: 'userPerson', title: '操作人', width: 170,align: "center"}
        ,{field: 'status', title: '审核状态', width: 180,align: "center",
          templet:function(res){
            if(res.status=='1'){
              return '未审核';
            }if(res.status=='2'){
              return '审核中';
            }if(res.status=='3'){
              return '审核通过';
            }else{
              return '审核未通过';
            }
          }
          }
        ,{title: '操作', width: 240, toolbar: '#barDemo', align: "center"}
      ]]
      , page: true //开启分页
      , limit: 5 //默认分页条数
      , limits: [10, 20, 30] //自定义分页数据选项
      , id: 'PurchaseTable', //用于绑定模糊查询条件等等
      done: function () {
        $("[data-field='id']").css('display','none');
        table.resize('PurchaseTable');
      }
    });
    //查询
    $('.btn-search').on('click', function () {
      var number = $('#number').val();
      var start_time = $('#start_time').val();
      var end_time = $('#end_time').val();
      var status = $('#status').val();
      var lowMoney = $('#lowMoney').val();
      var highMoney = $('#highMoney').val();
      table.reload('PurchaseTable', {
        url: '/PurchaseOrder/getAllPurchaseOrderAuditList',
        method: 'post',
        dataType: 'json',
        where: { //设定异步数据接口的额外参数，任意设
          number: number,
          start_time: start_time,
          start_time: start_time,
          end_time: end_time,
          status: status,
          lowMoney: lowMoney,
          highMoney: highMoney
        },
        page: {
          curr: 1 //重新从第 1 页开始
        }
      });
    });
    form.render();
    //工具条事件
    table.on('tool(PurchaseTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
      var data = obj.data; //获得当前行数据
      var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
      if (layEvent === 'detail') {
        json = JSON.stringify(data);
        layui.use('layer', function () {
          layer.open({
            type: 2,
            shift: 2,
            title: '审核',
            area: ['1000px', '700px'],
            closeBtn: 1,
            shadeClose: false,
            content: 'purchase/purchaseExamine/purchaseExamine.jsp',
            success: function () {
            },
            cancel: function () {
            layer.closeAll()
            $('.btn-search').click();
          }
          });
        });
      }
    });
  });
</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="detail">审核</a>
</script>
</body>
</html>
